#include <iostream>
#include <vector>

using namespace std;

class Solution {
private:
    struct TreeNode {
        int64_t val;
        int count = 1;
        TreeNode* left = nullptr;
        TreeNode* right = nullptr;
        TreeNode(int x) : val(x) {};
    };
    void search(TreeNode*& node, int64_t& lower, int64_t& upper, int& count) {
        if (node == nullptr) {
            return;
        }
        if (lower > node->val) {
            search(node->right, lower, upper, count);
        } else if (upper < node->val) {
            search(node->left, lower, upper, count);
        } else {
            count += node->count;
            search(node->left, lower, node->val, count);
            search(node->right, node->val, upper, count);
        }
    }
    void insert(TreeNode*& node, int64_t& val) {
        if (node == nullptr) {
            node = new TreeNode(val);
            return;
        }
        if (val < node->val) {
            insert(node->left, val);
        } else if (val > node->val) {
            insert(node->right, val);
        } else {
            node->count++;
        }
    }
public:
    int countRangeSum(vector<int>& nums, int lower, int upper) {
        if (nums.size() == 0) {
            return 0;
        }
        TreeNode* head = nullptr;
        int64_t sum = 0;
        int ans = 0;
        for (int num : nums) {
            sum += num;
            int64_t l = sum - upper;
            int64_t u = sum - lower;
            if (sum >= lower && sum <= upper) {
                ans++;
            }
            search(head, l, u, ans);
            insert(head, sum);
        }
        return ans;
    }
};

int main() {
    vector<int> input = {0};
    Solution solution;
    int output = solution.countRangeSum(input, 0, 0);
    cout << output << endl;
    return 0;
}